<!-- 员工登录后的添加司机的服务页面enterdriver1.php  -->
<!DOCTYPE html>
<html>

<head>
    <title>客户注册 | 汽车租赁</title>
</head>
<?php session_start(); ?>
<link rel="shortcut icon" type="image/png" href="assets/img/P.png.png">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/fonts/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/customerlogin.css">
<link rel="stylesheet" href="assets/w3css/w3.css">
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>

<body>
    <!-- 导航栏 -->
    <?php
    include './nav.php';
    ?>

    <?php
    // 包含数据库连接文件
    require 'connection.php';

    // 与数据库建立连接
    $conn = Connect();

    // 从 POST 请求中获取并清洗司机信息数据
    $driver_name = $conn->real_escape_string($_POST['driver_name']);
    $dl_number = $conn->real_escape_string($_POST['dl_number']);
    $driver_phone = $conn->real_escape_string($_POST['driver_phone']);
    $driver_address = $conn->real_escape_string($_POST['driver_address']);
    $driver_gender = $conn->real_escape_string($_POST['driver_gender']);
    $client_username = $_SESSION['login_client'];
    $driver_availability = "yes";

    // 构建插入司机信息的 SQL 语句
    $query = "INSERT into driver(driver_name, dl_number, driver_phone, driver_address, driver_gender, client_username, driver_availability) 
    VALUES('" . $driver_name . "','" . $dl_number . "','" . $driver_phone . "','" . $driver_address . "','" . $driver_gender . "','"
        . $client_username . "','" . $driver_availability . "')";

    // 执行 SQL 插入操作
    $success = $conn->query($query);

    // 判断插入操作是否成功
    if (!$success) {
    ?>
        <div class="container">
            <div class="jumbotron" style="text-align: center;">
                具有相同车牌号的车辆已存在！
                <br><br>
                <a href="entercar.php" class="btn btn-default"> 返回 </a>
            </div>
        </div>
    <?php
    } else {
        // 插入操作成功，重定向到 enterdriver.php 页面
        header("location: enterdriver.php");
    }

    // 关闭数据库连接
    $conn->close();
    ?>

</body>
<footer class="site-footer">
    <div class="container">
        <hr>
        <div class="row">
            <div class="col-sm-6">
                <h5>© <?php echo date("Y"); ?> 汽车租赁</h5>
            </div>
        </div>
    </div>
</footer>

</html>